<template>
    <a-modal
      :title="title"
      :width="1200"
      :visible="visible"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭"
    >
      <a-spin :spinning="confirmLoading">
        <a-form-model :model="model" :form="form" :rules="rules" ref="form" layout="vertical">
          <a-row class="form-row" :gutter="16">
            <a-col :span="6">
              <a-form-model-item label="公司" prop="workshop">
                <j-dict-select-tag
                  dictCode="crm_company,name,id"
                  v-model="model.company"
                  placeholder="请选择组织"
                >
                </j-dict-select-tag>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="车间" prop="workshop">
                <j-dict-select-tag placeholder="请选择车间" v-model="model.workshop" dictCode="workshop" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="工序" prop="workshop">
                <j-dict-select-tag
                  dictCode="working_procedure"
                  v-model="model.workingProcedure"
                  placeholder="请选择工序"
                  disabled
                >
                </j-dict-select-tag>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="开始时间" prop="startTime">
                <a-date-picker placeholder="请输入" show-time v-model="startTime" style="width: 100%" @change="changeStartTime"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="16">
            <a-col :span="6">
              <a-form-model-item label="结束时间" prop="endTime">
                <a-date-picker placeholder="请输入" show-time v-model="endTime" style="width: 100%"  @change="changeEndTime"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="车号" prop="deviceNo">
                <a-input placeholder="请输入" v-model="model.deviceNo" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="机型" prop="deviceModel">
                <a-input placeholder="请输入" v-model="model.deviceModel" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="品种类型" prop="productCategory">
                <a-input placeholder="请输入" v-model="model.productCategory" style="width: 100%" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="16">
            <a-col :span="6">
              <a-form-model-item label="品种" prop="productType">
                <j-dict-select-tag placeholder="请选择品种" v-model="model.productType"
                                   dictCode="crm_product_type_spooling,product_type,id"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="支数" prop="productBranch">
                <a-input placeholder="请输入" v-model="model.productBranch" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="看台定额" prop="fixedMachinesNum">
                <a-input placeholder="请输入" v-model="model.fixedMachinesNum" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="锭数" prop="ingots">
                <a-input placeholder="请输入" v-model="model.ingots" style="width: 100%" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="16">
            <a-col :span="6">
              <a-form-model-item label="定额产量" prop="weight">
                <a-input placeholder="请输入" v-model="model.weight" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="单价" prop="outputPrice">
                <a-input placeholder="请输入" v-model="model.outputPrice" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="品种系数" prop="productTypeCoefficient">
                <a-input placeholder="请输入" v-model="model.productTypeCoefficient" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="单价系数" prop="unitPriceCoefficient">
                <a-input placeholder="请输入" v-model="model.unitPriceCoefficient" style="width: 100%" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="16">
            <a-col :span="6">
              <a-form-model-item label="涡流纺换条单价" prop="changeStripUnitPrice">
                <a-input placeholder="请输入" v-model="model.changeStripUnitPrice" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="是否托盘" prop="isPlate">
                <a-input placeholder="请输入" v-model="model.isPlate" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="系数调整" prop="coefficientAdjust">
                <a-input placeholder="请输入" v-model="model.coefficientAdjust" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
            </a-col>
          </a-row>
        </a-form-model>
      </a-spin>
    </a-modal>
  </template>

    <script>
  import { httpAction } from '@/api/manage'
  import JEditor from '@/components/jeecg/JEditor'
  import JSwitch from '@/components/jeecg/JSwitch'
  export default {
    name: 'LuoTongPinZhongGongDingCanShuModal',
    components: {
      JEditor,
      JSwitch,
    },
    props:{
      planTime: String,
    },
    data() {
      return {
        title: '操作',
        visible: false,
        disable: true,
        startTime:'',
        endTime:'',
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        rules: {},
        url: {
          add: '/crm_product_type_params_spooling/crmProductTypeParamsSpooling/add',
          edit: '/crm_product_type_params_spooling/crmProductTypeParamsSpooling/edit',
        },
      }
    },
    created() {},
    methods: {
      changeStartTime(date, dateString){
        this.model.startTime = dateString
      },
      changeEndTime(date, dateString){
        this.model.endTime = dateString
      },
      add() {
        this.disable = false
        this.model = Object.assign({}, {})
        this.model.workingProcedure = 7
        this.model.company = '1771136798305476610'
        this.startTime = this.planTime + " 00:00:00"
        this.endTime = this.planTime + " 23:59:59"
        this.model.startTime = this.planTime + " 00:00:00"
        this.model.endTime = this.planTime + " 23:59:59"
        this.edit({}, 1)
      },
      edit(record, isEdit) {
        if (isEdit != 1) {
          this.model = Object.assign({}, record)
          this.startTime = this.model.startTime
          this.endTime = this.model.endTime
        }

        this.visible = true
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.disable = true
        this.$refs.form.resetFields();
      },

      handleOk() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.model.id) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'put'
            }
            let formData = Object.assign(this.model)
            console.log('formData', formData)
            //时间格式化
            httpAction(httpurl, formData, method)
              .then((res) => {
                if (res.success) {
                  this.$message.success(res.message)
                  this.$emit('ok')
                } else {
                  this.$message.warning(res.message)
                }
              })
              .finally(() => {
                this.confirmLoading = false
                this.close()
              })
          } else {
            return false
          }
        })
      },

      handleCancel() {
        this.close()
      },
    },
  }
  </script>

    <style scoped></style>
